//
//  ShipView.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-4-20.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//

#import "ShipView.h"
#import "WeaponView.h"

@implementation ShipView

+(id) viewWithModelId:(int) modelId anchorPoint:(CGPoint) anchorPoint
{
    return [[[self alloc] initWithModelId:modelId anchorPoint:anchorPoint] autorelease]; 
}

-(id) initWithModelId:(int) modelId anchorPoint:(CGPoint) anchorPoint
{
    self = [super init]; 
	
	if (self!= nil) 
    {
        //船的背景层
        CCSprite* shipBG = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"ship%d.png", modelId]];
        shipBG.anchorPoint = anchorPoint;
        [self addChild:shipBG];
        
        //船的尾焰
        _wakeFlameAction = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"wakeFlame.png", modelId]];
        _wakeFlameAction.anchorPoint = ccp(0.5, 1);
        _wakeFlameAction.position = ccp(0, -shipBG.contentSize.height * anchorPoint.y + 14);
        [self addChild:_wakeFlameAction];
        [self showWakeFlame:NO];
    }
    
    return self;
}

/**
	 是否播放尾焰特效
	@param isShow 是否播放，Yes播放，No不播放
 */
-(void) showWakeFlame:(BOOL)isShow
{
    if(isShow)
    {
        _wakeFlameAction.visible = YES;
    }
    else
    {
        _wakeFlameAction.visible = NO;
    }
    
    //TODO 以后加动画
//    NSMutableArray *weaponAnimFrames = [NSMutableArray array];
//    for(int i = 0; i < 2; i++) 
//    {
//        [weaponAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
//                                     [NSString stringWithFormat:@"weapon%d_%d.png", _modelId, i]]];
//    }
//    
//    CCAnimation *weaponAnim = [CCAnimation animationWithFrames:weaponAnimFrames delay:0.1f];
//    
//    CCAnimate* animate = [CCAnimate actionWithAnimation:weaponAnim];
//    CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate]; 
//    [_fireAction runAction:repeat];
}

- (void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
